package pl.com.qapps.unity;

import java.util.concurrent.TimeUnit;

import pl.com.qapps.unity.Quicklist.Action;
import pl.com.qapps.unity.Quicklist.Radio;
import pl.com.qapps.unity.Quicklist.RadioGroup;
import pl.com.qapps.unity.Quicklist.Select;

/**
 * @author Jakub Dykowski
 * 
 */
class TestUnityLauncher {
	public static void main(String[] args) throws InterruptedException,
			LauncherException {

		final UnityLauncher eclipse = UnityLauncher
				.getForDesktopFile("Eclipse.desktop");
		eclipse.setUrgent(true);
		Quicklist ql = new Quicklist();

		Select countVisible = new Select("Count visible") {

			@Override
			public void onSelected(boolean selected) {
				eclipse.setCountVisible(selected);
			}

		};
		ql.add(countVisible);

		Select progressVisible = new Select("Progress visible") {

			@Override
			public void onSelected(boolean selected) {
				eclipse.setProgressVisible(selected);
			}

		};
		ql.add(progressVisible);

		Select urgent = new Select("Urgent", eclipse.isUrgent()) {

			@Override
			public void onSelected(boolean selected) {
				eclipse.setUrgent(selected);
			}

		};
		ql.add(urgent);
		Action countIncrement = new Action("Count++", new Runnable() {

			@Override
			public void run() {
				eclipse.setCount(eclipse.getCount() + 1);
			}

		});
		ql.add(countIncrement);
		eclipse.setQuicklist(ql);

		Quicklist q = new Quicklist();

		RadioGroup<String> state = new RadioGroup<String>() {

			@Override
			public void onSelected(String option) {
				System.out.println("RadioGroup state: " + option);
			}

		};
		Radio<String> on = new Radio<>("On", state, "ON");
		Radio<String> off = new Radio<>("Off", state, "OFF");
		q.add(on);
		q.add(off);
		q.add(new Quicklist.Separator());

		q.add(new Action("Label nr 1", null));
		q.add(new Action("Label nr 2", new Runnable() {

			public void run() {
				System.out.println("Label nr has been activated!!");
			}

		}));
		Select cb = new Select("This is CheckBox", false) {

			@Override
			public void onSelected(boolean selected) {
				System.out.println("Checkbox is selected: " + selected);
				// if(selected)
				// setSelected(false);
			}

		};
		q.add(cb);

		UnityLauncher kadu = UnityLauncher.getForDesktopFile("kadu.desktop");

		long start = System.currentTimeMillis();
		kadu.setQuicklist(q);
		long stop = System.currentTimeMillis();

		System.err.println("duration: " + (stop - start) + " miliseconds");

		kadu.setUrgent(true);
		kadu.setCount(99);
		kadu.setCountVisible(true);
		kadu.setProgress(0.5);
		kadu.setProgressVisible(true);

		TimeUnit.SECONDS.sleep(2);

		kadu.setCount(3);
		kadu.setProgress(0.75);
		kadu.setUrgent(false);

		System.out.println(kadu.isUrgent());
		System.out.println(kadu.isCountVisible());
		System.out.println(kadu.isProgressVisible());
		System.out.println(kadu.getAppUri());
		System.out.println(kadu.getCount());
		System.out.println(kadu.getProgress());

		cb.setSelected(true);
		// cb.setLabel("Just a Checkbox");
		// // kadu.setQuicklist(q);
		// // kadu.setQuicklist(q);
		// q.remove(off);
		// System.out.println(q.subList(0, 1).size() + " should be 1");
		// q.subList(0, 2).add(1,off);
		// System.out.println(q);
		//
		// // eclipse.close();
		//
		// System.out.println(ql);
		// System.out.println(q);
		// System.out.println(q.subList(2, 5));
		// // q.subList(3, 5).clear();
		// System.out.println(q);
		// // q.subList(0, 2).add(new Quicklist.Separator());
		// // q.addAll(3, ql);
		// System.out.println(q);
		// // for(int i = 0; i < 100; i++)
		// cb.setSelected(!cb.isSelected());
		for (int i = 0; i <= 30; i++) {
			kadu.setCount(i);
			TimeUnit.MILLISECONDS.sleep(200);
			if (i == 1000)
				System.out.println("setting 999");
		}
		TimeUnit.SECONDS.sleep(2);
		// System.out.println(kadu.getCount());
		// kadu.setCount(100);
		// kadu.setProgress(1D);

	}
}
